const basex = require('base-x');
const buffer = require("buffer").Buffer;
const ALPHABETS = "KDABCEFGHIJLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+~-";

const base65 = basex(ALPHABETS);

/**
 * @returns {String}
 * @param {String} str 
 */
function encode(str){
  return base65.encode(buffer.from(str));
}

/**
 * @returns {String}
 * @param {String} str 
 */
function decode(str){
  return base65.decode(str).toString();
}

module.exports = {
  encode,
  decode
}